package com.yanqu.road.server.cmd.variety;

import com.yanqu.road.pb.variety.VarietyProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.match.CrossMatchMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;

/**
 * @author ：zfr
 * @date ：2021/2/20 15:50
 */
@Cmd(code = CrossProtocol.C_VARIETY_SYNC_VARIETY_DETAIL_DATA, desc = "同步杂艺详细数据")
public class SyncVarietyDetailCrossCmd extends CrossCommand {
    private VarietyProto.SyncVarietyDetailReqMsg msg;
    private VarietyProto.SyncVarietyDetailRespMsg.Builder respMsg;
    private long playerId;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        msg = VarietyProto.SyncVarietyDetailReqMsg.parseFrom(packet.getBytes());
        respMsg = VarietyProto.SyncVarietyDetailRespMsg.newBuilder();
        playerId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossMatchMgr.syncVarietyDetailData(serverId, msg, respMsg);
    }

    @Override
    public void sendData() {
        YanQuMessage message = YanQuMessageUtils.buildMessage(ClientProtocol.U_VARIETY_SYNC_VARIETY_DETAIL_DATA, respMsg);
        MessageHelper.sendPacket(serverId, playerId, message);
    }
}
